package com.lagou.edu.ad.controller;

import com.lagou.edu.dto.PromotionAdDTO;
import com.lagou.edu.dto.PromotionSpaceDTO;
import com.lagou.edu.remote.AdRemoteService;
import com.lagou.edu.reponse.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ad")
public class BossAdController {

    @Autowired
    private AdRemoteService adRemoteService;

    /**
     * 获取所有广告位
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/space/getAllSpaces")
    public ResponseDTO<List<PromotionSpaceDTO>> getAllSpace() throws Exception {
        List<PromotionSpaceDTO> dtoList = adRemoteService.getAllSpaces();
        return ResponseDTO.success(dtoList);
    }

    /**
     * 增加和编辑广告位
     *
     * @param promotionSpaceDTO
     * @return
     */
    @PostMapping("/space/saveOrUpdateSpace")
    public ResponseDTO saveOrUpdateSpace(@RequestBody PromotionSpaceDTO promotionSpaceDTO) {
        return adRemoteService.saveOrUpdateSpace(promotionSpaceDTO);
    }

    /**
     * 根据id查询广告位
     *
     * @param id
     * @return
     */
    @GetMapping("/space/getAdSpaceById")
    public ResponseDTO<PromotionSpaceDTO> getAdSpaceById(@RequestParam("id") Integer id) {
        PromotionSpaceDTO dto = adRemoteService.getAdSpaceById(id);
        return ResponseDTO.success(dto);
    }

    /**
     * 后台获取所有的广告
     *
     * @return
     */
    @GetMapping("/getAdList")
    public ResponseDTO<List<PromotionAdDTO>> getAdList() {
        List<PromotionAdDTO> adList = adRemoteService.getAdList();
        return ResponseDTO.success(adList);
    }

    /**
     * 后台增加和编辑广告
     *
     * @param promotionAdDTO
     * @return
     */
    @PostMapping("/saveOrUpdateAd")
    public ResponseDTO saveOrUpdateAd(@RequestBody PromotionAdDTO promotionAdDTO) {
        return adRemoteService.saveOrUpdateAd(promotionAdDTO);
    }

    /**
     * 根据id查询广告
     *
     * @param id
     * @return
     */
    @GetMapping("getAdById")
    public ResponseDTO<PromotionAdDTO> getAdById(@RequestParam("id") Integer id) {
        PromotionAdDTO dto = adRemoteService.getAdById(id);
        return ResponseDTO.success(dto);
    }

}